package com.sanerzone.smscenter.biz.VerifyInterface.util;

import com.sanerzone.smscenter.biz.entity.TemplateRoute;
import com.sanerzone.smscenter.biz.message.SMSMTMessage;
import org.marre.util.StringUtil;

import java.util.List;
import java.util.Map;

public class FilterUtil {
    /**
     * 去除在黑名单中的号码
     * @param targetPhone
     * @param allPhone
     * @param index
     * @return
     */
    public static String removePhone(String targetPhone,String allPhone,int index){
        if (targetPhone.equals( allPhone )){
            return "";
        }
        if(index==0){//第一个位置剔除
            allPhone=allPhone.replaceFirst(targetPhone+",","" );
        }else{
            allPhone=allPhone.replaceFirst(","+targetPhone,"" );
        }

        return allPhone;
    }

    /**
     * 返回拼装好的电话号码，逗号隔开
     * @param phonesList
     * @return
     */
    public static String getPhonesString(List<String> phonesList){
        StringBuffer sb=new StringBuffer("");
        if (phonesList.size()==1){
            return phonesList.get(0 );
        }else{
            sb.append( phonesList.get(0) );
            for(int i=1;i<phonesList.size();i++){
                sb.append("," +phonesList.get( i ) );
            }
            return sb.toString();

        }
    }


    public static String getPhonesString(List<String> phonesList,int startIndex,int endIndex){
       StringBuffer sb=new StringBuffer( );
       sb.append( phonesList.get( startIndex ) );
       for(int i=startIndex+1;i<endIndex;i++){
           sb.append( ","+phonesList.get( i ) );
       }
       return sb.toString();
    }


    public static void setSplit(String phone,SMSMTMessage smsmtMessage){

            smsmtMessage.setShowLevel( 2 );
            smsmtMessage.setNeedSplit( 1 );


    }

    public static void setNeedSplit(SMSMTMessage smsmtMessage){
        if (smsmtMessage.getSendStatus().startsWith( "V" )||smsmtMessage.getSendStatus().startsWith( "D" )){
            smsmtMessage.setNeedSplit( 0 );
            smsmtMessage.setShowLevel( 2 );
        }
    }

    public static boolean smsTypeBelong(String smsType,String groupId){
        return true;
    }
    public static boolean templateRouteMatch(TemplateRoute templateRoute,String content){
        String templateContent=templateRoute.getTemplateContent();
        boolean isMatch=false;
        int matchCount=0;
        String[] templates= templateContent.split( "\\*" );
        for (int i=0;i<templates.length;i++){
            //得到的是第一个劈开来的每一个模板
            String templateStr=templates[i];
            if (content.contains( templateStr )){
                matchCount++;
            }
        }
        if (matchCount==templates.length){
            isMatch=true;
        }
        return isMatch;



    }

}
